package xpn.platform.common.exception;

/**
 * 错误异常编码枚举类
 *
 * @author duwei
 * @version 2017/9/5 9:42
 */
public enum XpnExceptionCodeEnum {

	/**业务异常*/
	BUSINESS_EXCEPTION_HTTP_STATUS(601, "Business exception!"),

	/**规则脚本运行失败*/
	RULE_SCRIPT_FAILED(1, "Rule script failed to run!"),

	/**用户未找到*/
	USER_NOT_FOUND(2, "User not found!"),

	/**用户被锁定*/
	USER_ACCOUNT_LOCKED(3, "User account locked!"),

	/**需要认证*/
	NEED_AUTHENTICATION(4, "Need Authentication!"),

	/**会话超时*/
	SESSION_OUT_OF_DATE(41, "Session out of date!"),

	/**需要权限*/
	NEED_PERMISSION(5, "Need permission!"),

	/**shiro异常*/
	SHIRO_ERROR(6, "Shiro error!"),

	/**验证失败*/
	VALIDATION_FAILED(7, "Validation failed!"),

	/**登录失败*/
	LOGIN_FALED(8, "Login failed!"),

	/**密码强度验证失败*/
	PASSWORD_FALED(10, "密码强度不足!"),

	/**上传文件失败*/
	UPLOAD_FILE_FALED(9, "enctype=\"multipart/form-data\" not found!");



	private final Integer errorCode;

	private final String errorMessage;

	XpnExceptionCodeEnum(Integer errorCode, String errorMessage) {
		this.errorCode = errorCode;
		this.errorMessage = errorMessage;
	}

	public Integer getErrorCode() {
		return errorCode;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	/**
	 * Return a string representation of this status code.
	 */
	@Override
	public String toString() {
		return Integer.toString(this.errorCode);
	}

	/**
	 * Return the enum constant of this type with the specified numeric value.
	 *
	 * @param errorCode
	 *            the numeric value of the enum to be returned
	 * @return the enum constant with the specified numeric value
	 * @throws IllegalArgumentException
	 *             if this enum has no constant for the specified numeric value
	 */
	public static XpnExceptionCodeEnum valueOf(int errorCode) {
		for (XpnExceptionCodeEnum code : values()) {
			if (code.errorCode == errorCode) {
				return code;
			}
		}
		throw new IllegalArgumentException("No matching constant for [" + errorCode + "]");
	}
}
